import { AcitivityDefItem, ActivityDefType } from "./models";
import req from "/@/api/req";

export const Api = {
  activitySchedule: "mall-ums/api/v1/marketing/activity-schedules",
  activitySchedulePage: "mall-ums/api/v1/marketing/activity-schedules/page",
  activityScheduleForm: "mall-ums/api/v1/marketing/activity-schedules/{id}/form",
  activityScheduleNullify: "mall-ums/api/v1/marketing/activity-schedules/nullify",
  activityScheduleReview: "mall-ums/api/v1/marketing/activity-schedules/review",
  activityScheduleList: "mall-ums/api/v1/marketing/activity-schedules/list",

  activityCoupon: "mall-ums/api/v1/marketing/activity-coupons",
  activityCouponPage: "mall-ums/api/v1/marketing/activity-coupons/page",
  activityCouponForm: "mall-ums/api/v1/marketing/activity-coupons/{id}/form",
  activityCouponNullify: "mall-ums/api/v1/marketing/activity-coupons/nullify",
  activityCouponReview: "mall-ums/api/v1/marketing/activity-coupons/review",
  activityCouponScope: "mall-ums/api/v1/marketing/activity-coupons-scopes/detail",

  activityDetail: "mall-ums/api/v1/marketing/activity-details",
  activityDetailPage: "mall-ums/api/v1/marketing/activity-details/page",
  activityDetailForm: "mall-ums/api/v1/marketing/activity-details/{id}/form",
  activityDetailNullify: "mall-ums/api/v1/marketing/activity-details/nullify",
  activityDetailReview: "mall-ums/api/v1/marketing/activity-details/review",
  activityDetailScope: "mall-ums/api/v1/marketing/activity-details-scopes/detail",
};

export function addActivityCommon(data: Partial<AcitivityDefItem>, activityDefType: ActivityDefType) {
  return req.commonPost(Api[activityDefType], data, { useGlobalLoading: true });
}

export function delActivityCommon(id: string, activityDefType: ActivityDefType) {
  return req.delete(
    {
      url: Api[activityDefType] + "/" + id,
    },
    {
      useGlobalLoading: true,
    }
  );
}

export function updateActivityCommon(data: Partial<AcitivityDefItem>, activityDefType: ActivityDefType) {
  return req.put(
    {
      url: Api[activityDefType],
      data,
    },
    {
      useGlobalLoading: true,
    }
  );
}
export function getActivityCommon(id: number, activityDefType: ActivityDefType) {
  return req.commonGet<AcitivityDefItem>(
    Api[activityDefType + "Form"].replace("{id}", id + ""),
    {},
    { useGlobalLoading: true }
  );
}

export function getActivityScope(id: number, activityDefType: ActivityDefType) {
  return req.commonGet<AcitivityDefItem>(
    Api[activityDefType + "Scope"],
    {
      id,
    },
    { useGlobalLoading: false }
  );
}

export function reviewActivityCommon(id: number, activityDefType: ActivityDefType) {
  return req.put(
    {
      url: Api[activityDefType + "Review"],
      data: { id },
    },
    { useGlobalLoading: true }
  );
}

export function nullifyActivityCommon(id: number, activityDefType: ActivityDefType) {
  return req.put(
    {
      url: Api[activityDefType + "Nullify"],
      data: { id },
    },
    { useGlobalLoading: true }
  );
}

export function getActivityScheduleList() {
  return req.commonGet<AcitivityDefItem[]>(Api.activityScheduleList, {}, { useGlobalLoading: false });
}
